package com.caocaog.market.entity.dto;

import com.caocaog.market.entity.GoodsSpec;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * 商品规格数据传输对象
 *
 * @author chechen
 * @date 2022-04-18
 */
@Getter
@Setter
public class GoodsSpecDTO implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "规格id")
    private String id;

    @Deprecated
    @ApiModelProperty(value = "规格图片")
    private String pictureSku;

    @ApiModelProperty(value = "规格名称")
    private String nameSku;

    @ApiModelProperty(value = "规格价格")
    private String priceSku;

    @Min(value = 0, message = "重量不能小于0")
    @ApiModelProperty(value = "重量(kg)")
    private String weightSku;

    @Min(value = 0, message = "重量不能小于0")
    @ApiModelProperty(value = "重量(g)")
    private Integer weightGSku;

    @Min(value = 0, message = "库存不能小于0")
    @ApiModelProperty(value = "库存")
    private Integer stockSku;

    @NotNull(message = "规格打包费不能为空")
    @ApiModelProperty(value = "打包费")
    private String packFeeSku;


    public GoodsSpec toGoodsSpec() {
        return new GoodsSpec()
                .setId(this.id)
                .setName(this.nameSku)
                .setPrice(this.priceSku)
                .setWeight(this.weightSku)
                .setWeightG(this.weightGSku)
                .setStock(this.stockSku)
                .setPackFee(this.packFeeSku);
    }
}
